﻿'Imports System.Diagnostics

'Namespace Instrumentacao

'    ''' <summary>
'    ''' Esta classe Registra o tempo de execucao de um metodo.
'    ''' Deve ser utilizado usando a forma USING do .NET.
'    ''' </summary>
'    ''' <remarks></remarks>
'    Public Class RegistroTempoExecucao
'        Implements IDisposable

'        Private stopWatch As New Stopwatch()
'        Private ReadOnly log As ILogger
'        Private id As Integer

'        Public Sub New(ByVal tipo As Type, ByVal metodo As String)
'            ' Usando reflexao para pegar o tipo da classe e o metodo que chamou este construtor.
'            'Dim stack As StackFrame = New StackFrame(1, False)
'            'Dim tipo As Type = stack.GetMethod.ReflectedType
'            'Dim metodo As System.Reflection.MethodBase = stack.GetMethod()

'            log = LoggerFactory.GetLogger(tipo)

'            ' Gerando um numero randomico para servir de ID do metodo sendo executado no momento de execucao.
'            Dim random As New Random()
'            id = random.Next

'            stopWatch.Start()

'            log.Debug("Execucao ID '" & id & "'. Metodo: '" & metodo & "'. ")
'        End Sub


'        Private disposedValue As Boolean = False        ' To detect redundant calls

'        ' IDisposable
'        Protected Overridable Sub Dispose(ByVal disposing As Boolean)
'            If Not Me.disposedValue Then
'                If disposing Then
'                    stopWatch.Stop()
'                    Dim tempoDeExecucao As Long = stopWatch.ElapsedMilliseconds
'                    log.Debug("Fim execucao ID '" & id & "'. Tempo: " & tempoDeExecucao)
'                End If
'                stopWatch = Nothing
'            End If
'            Me.disposedValue = True
'        End Sub

'#Region " IDisposable Support "
'        ' This code added by Visual Basic to correctly implement the disposable pattern.
'        Public Sub Dispose() Implements IDisposable.Dispose
'            ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
'            Dispose(True)
'            GC.SuppressFinalize(Me)
'        End Sub
'#End Region

'    End Class
'End Namespace
